package com.baomidou.mybatisplus.generator.config.rules;//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public enum NamingStrategy {
	no_change,
	underline_to_camel;

	private NamingStrategy() {
	}

	public static String underlineToCamel(String name) {
		if (StringUtils.isBlank(name)) {
			return "";
		} else {
			String tempName = name;
			if (StringUtils.isCapitalMode(name) || StringUtils.isMixedMode(name)) {
				tempName = name.toLowerCase();
			}

			StringBuilder result = new StringBuilder();
			String[] camels = tempName.split("_");
			Arrays.stream(camels).filter((camel) -> {
				return !StringUtils.isBlank(camel);
			}).forEach((camel) -> {
				if (result.length() == 0) {
					result.append(camel.toLowerCase());
				} else {
					result.append(capitalFirst(camel));
				}

			});
			return result.toString();
		}
	}

	/** @deprecated */
	@Deprecated
	public static String removePrefix(String name, String... prefix) {
		Set<String> set = new HashSet(Arrays.asList(prefix));
		return removePrefix(name, (Set)set);
	}

	public static String removePrefix(String name, Set<String> prefix) {
		if (StringUtils.isBlank(name)) {
			return "";
		} else {
			return null != prefix ? (String)prefix.stream().filter((pf) -> {
				return name.toLowerCase().matches("^" + pf.toLowerCase() + ".*");
			}).findFirst().map((pf) -> {
				return name.replaceFirst(pf.toLowerCase(), "");
			}).orElse(name) : name;
		}
	}

	public static boolean isPrefixContained(String name, String... prefix) {
		return null != prefix && !StringUtils.isBlank(name) ? Arrays.stream(prefix).anyMatch((pf) -> {
			return name.toLowerCase().matches("^" + pf.toLowerCase() + ".*");
		}) : false;
	}

	/** @deprecated */
	@Deprecated
	public static String removePrefixAndCamel(String name, String[] tablePrefix) {
		return underlineToCamel(removePrefix(name, tablePrefix));
	}

	public static String removePrefixAndCamel(String name, Set<String> tablePrefix) {
		return underlineToCamel(removePrefix(name, tablePrefix));
	}

	public static String capitalFirst(String name) {
		return StringUtils.isNotBlank(name) ? name.substring(0, 1).toUpperCase() + name.substring(1) : "";
	}
}
